package cn.kgc.springmvc.controller;

import cn.kgc.springmvc.util.ResponseResult;
import org.springframework.web.bind.annotation.*;

/**
 * @author 课工场
 * @date 2024/2/28
 * @description 构建web项目是 为了让请求的路径更加的简洁可以遵循restful的设计风格来编写url
 * <p>
 * 查询数据列表       /rest/list
 * 根据id查询数据    /rest/getById?id=10
 * <p>
 * /rest   crud
 * <p>
 * /rest    get        查询
 * /rest/10    get     根据id查询
 * /rest    post       添加
 * /rest    put        修改
 * /rest/10    delete     删除
 */

@RequestMapping("rest")
@RestController
public class RestfulController {


    // 添加
    @PostMapping
    public ResponseResult add() {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setMessage("添加请求被接收");
        return  responseResult;
    }
    // 删除
    @DeleteMapping("{id}")
    public ResponseResult delete(@PathVariable("id") Integer id) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setMessage("删除请求被接收"+id);
        return  responseResult;
    }
    // 修改
    @PutMapping
    public ResponseResult edit() {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setMessage("修改请求被接收");
        return  responseResult;
    }

    // 查询
    @GetMapping
    public ResponseResult select() {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setMessage("查询请求被接收");
        return  responseResult;
    }

    // 根据id查询   /rest/10
    @GetMapping("{id}")
    public ResponseResult selectById(@PathVariable("id") Integer id) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setMessage("查询请求被接收"+id);
        return  responseResult;
    }

}
